// 怎么在一个js中引入另外一个js
//@import?

// function hasClass(obj,cls){
//     //console.log("in");
//     return obj.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
// }

// function addClass(obj,cls){
//     if(!hasClass(obj,cls)){
//         //效果一样
//         //obj.classList.add(cls);
//         obj.className += " " + cls;
//     }
// }

// function removeClass(obj,cls){
//     if(hasClass(obj,cls)){
//         obj.classList.remove(cls);
//     }
// }

// function toggleClass(obj,cls){
//     if(hasClass(obj,cls)){
//         removeClass(obj,cls);
//     }else{
//         addClass(obj,cls);
//     }
// }


// personInfo js-change-model
//console.log('im in main.js');
// var setActive = document.getElementById('js-setNavActive');
// var ele = setActive.getElementsByTagName("li");
// console.log(ele.length);
window.onload = function(){
    var setActive = document.getElementsByClassName('js-setNavActive');
    console.log(setActive.length);
    //hasClass(setActive[0],js-setNavActive); no define
    //define hasClass addClass removeClass
    function hasClass(obj,cls){
    //console.log("in");
    return obj.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
    }

    function addClass(obj,cls){
        if(!hasClass(obj,cls)){
            //效果一样
            //obj.classList.add(cls);
            obj.className += " " + cls;
        }
    }

    function removeClass(obj,cls){
        if(hasClass(obj,cls)){
            obj.classList.remove(cls);
        }
    }

    function toggleClass(obj,cls){
        if(hasClass(obj,cls)){
            removeClass(obj,cls);
        }else{
            addClass(obj,cls);
        }
    }
    //
    function judgmentContent(){
        var content = document.getElementsByClassName('js-change-model');
        for(var i = 0; i < setActive.length ; i++){
            content[i].style.display = 'none';
            if(hasClass(setActive[i],'navActive')){
                content[i].style.display = 'block';
            }
        }

    }
    judgmentContent();
    //bind onclick
    for(var i = 0 ; i < setActive.length ; i++){
        setActive[i].onclick = function(){
            console.log('im onclik');
            // removeClass
            for(var j = 0 ; j < setActive.length ; j++){
                removeClass(setActive[j],'navActive');
            }
            //onclick add class
            addClass(this,'navActive');
            judgmentContent();
        }
    }


}
